package com.sxbbc.common.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sxbbc.common.core.entity.jz.AppClassification;
import com.sxbbc.common.core.entity.jz.ProcFirstClassifyMain;
import com.sxbbc.common.core.enums.EventEnums;
import com.sxbbc.common.core.mapper.jz.AppClassificationMapper;
import com.sxbbc.common.core.service.IAppClassificationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxbbc.common.core.service.IProcFirstClassifyMainService;
import com.sxbbc.common.core.utils.BasePage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * app分类图标信息表 服务实现类
 * </p>
 *
 * @author leehao
 * @since 2019-06-03
 */
@Service
public class AppClassificationServiceImpl extends ServiceImpl<AppClassificationMapper, AppClassification> implements IAppClassificationService {

    @Autowired
    private IProcFirstClassifyMainService procFirstClassifyMain;

    @Override
    public IPage<AppClassification> queryClassificationList(BasePage<AppClassification> page, AppClassification classification) {
        QueryWrapper<AppClassification> wrapper = new QueryWrapper<AppClassification>();
        if (classification.getPosition() != null) {
            wrapper.eq("position",classification.getPosition());
        }
        if (page.isPaging()) {
            super.page(page,wrapper);
        }else{
            List<AppClassification> list = super.list(wrapper);
            page.setRecords(list);
        }
        for (AppClassification c : page.getRecords()) {
            c.setEventName(EventEnums.getName(c.getEvent()));
            //分类名称
            if (StringUtils.isNotBlank(c.getUrl())) {
                ProcFirstClassifyMain first = procFirstClassifyMain.getById(c.getUrl());
                c.setClassifyName(first.getName());
            }
        }
        return page;
    }
}
